﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Common;
using Dao;
using Domain.Common;
using Domain.Officers;
using Microsoft.Xna.Framework;

namespace Domain
{
    /// <summary>
    /// 军阀势力
    /// </summary>
    public partial class Force
    {
        /// <summary>
        /// 任命地方长官
        /// </summary>
        public void ApointBuildingEphor()
        {
            foreach (var building in Buildings)
            {
                int maxScore = 0;//最大将领得分
                Officer mastser=null;
                foreach (var o  in building.OwnedOfficers)
                {
                    int score = o.Commander + o.Glamour + o.Intelligence + o.Politics + o.Strength;
                    if (score > maxScore)
                    {
                        maxScore = score;
                        mastser = o;
                    }
                }
                building.Master = mastser;
                System.Diagnostics.Debug.WriteLine("势力：{0} 城池：{1} 长官：{2}", building.Force.Name, building.Name, mastser != null ? mastser.FirstName + mastser.Name : "");
            }
        }
        /// <summary>
        /// 确定势力城池战略方针
        /// </summary>
        public void SureBuildingStrategy()
        {
            foreach (var building in Buildings)
            {
                bool c1=building.NearlyBuildings.Exists(x => x.ForceId == null );//附近有无主之城
                bool c2 = building.NearlyBuildings.Exists(x => x.ForceId != building.ForceId);//附近有敌对势力
                //武将风格决定势力策略
                if (this.Master.Style == OfficerStyle.Proactive)
                {
                    if(c1&&c2)
                         building.StrategyType=StrategyType.War;
                    else 
                        building.StrategyType=StrategyType.Send;
                }
                else if (this.Master.Style == OfficerStyle.Speculator)
                {
                     if(c1&&c2)
                         building.StrategyType=StrategyType.War;
                    else 
                        building.StrategyType=StrategyType.Normal;
                }
                else if (this.Master.Style == OfficerStyle.Kind)
                {
                    if (c2)
                        building.StrategyType = StrategyType.Defense;
                    else
                        building.StrategyType = StrategyType.Normal;
                }
                System.Diagnostics.Debug.WriteLine("城池:" + building.Name + " 战略为:" + EnumUtil.Getdescription(building.StrategyType));
               
            }
        } 
    }
}
